package com.bl.weilan.api.controller.institution;

import com.bl.weilan.api.controller.BaseController;
import com.bl.weilan.common.ApiResponseBody;
import com.bl.weilan.dao.model.InformationEntity;
import com.bl.weilan.dao.model.InstitutionEntity;
import com.bl.weilan.dao.model.InstitutionTeamEntity;
import com.bl.weilan.service.biz.informationType.InformationTypeService;
import com.bl.weilan.service.biz.institution.InstitutionService;
import com.bl.weilan.service.vo.company.CompanyListVo;
import com.bl.weilan.service.vo.informationtype.InformationTypeListVo;
import com.bl.weilan.service.vo.institution.InstitutionListVo;
import com.bl.weilan.service.vo.institution.InstitutionTeamListVo;
import com.bl.weilan.service.vo.institution.InstitutionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@Log4j2
@RequestMapping(value = {"/weilan/apis/institution"})
@Api(value = "通知类型相关", description = "机构")
public class InstitutionController extends BaseController {

    @Autowired
    InstitutionService institutionService;

    @ApiOperation(value = "通过行业id查询机构列表", notes = "通过行业id查询机构列表，排序类型 foundTime-时间 total-管理资本总量 caseNum-投资案例数 desc-降序 asc-升序")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tradeId", value = "行业id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "排序类型", required = true, paramType = "query", dataType = "String", defaultValue = "time"),
            @ApiImplicitParam(name = "order", value = "升序/降序", required = true, paramType = "query", dataType = "String", defaultValue = "desc"),
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_list"})
    public ApiResponseBody<InstitutionListVo> institutionList(
            @RequestParam(value = "tradeId", required = true) String tradeId,
            @RequestParam(value = "type", required = false, defaultValue = "time") String type,
            @RequestParam(value = "order", required = false, defaultValue = "desc") String order,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,

            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);
        InstitutionListVo institutionListVo = institutionService.getInstitutionLists(tradeId, type, order, pageable);

        return ApiResponseBody.createSuccessBody(institutionListVo);
    }

    @ApiOperation(value = "通过机构id查询公司列表", notes = "通过机构id查询公司列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "institutionId", value = "行业id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_company_list"})
    public ApiResponseBody<CompanyListVo> companyList(
            @RequestParam(value = "institutionId", required = true) String institutionId,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,

            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);
        CompanyListVo companyListVo = institutionService.getCompanyListVo(institutionId, pageable);

        return ApiResponseBody.createSuccessBody(companyListVo);
    }

    @ApiOperation(value = "通过机构id查询团队", notes = "通过机构id查询团队")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "institutionId", value = "行业id", required = true, paramType = "query", dataType = "institutionId"),
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_team_list"})
    public ApiResponseBody<InstitutionTeamListVo> institutionTeamListVoApiResponseBody(
            @RequestParam(value = "institutionId", required = true) String institutionId,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,

            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);
        InstitutionTeamListVo institutionTeamListVo = institutionService.getInstitutionTeamListVo(institutionId, pageable);

        return ApiResponseBody.createSuccessBody(institutionTeamListVo);
    }

    @ApiOperation(value = "查询机构详情", notes = "查询机构详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String")})
    @GetMapping(value = {"/get_detail"})
    public ApiResponseBody<InstitutionVo> institutionDetail(
            @RequestParam(value = "id", required = true) String id,
            HttpServletRequest request) {

        InstitutionVo institutionEntity = institutionService.getDetailById(id);

        return ApiResponseBody.createSuccessBody(institutionEntity);
    }

}
